import Vue from 'vue'
import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject){
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router);
export default new Router({
  routes: [
    {
      path: '/not-found',
      meta: {
        publicPath: true
      },
      component: ()=>import('@/pages/other-pages/NotFound')
    },
    {
      path: '*',
      redirect: '/not-found'
    },
    {
      path: '/',
      component: ()=>import('@/pages/index'),
      children: [
        {
          path: '/home',
          meta: {
            index: 1,
            publicPath: true
          },
          component: ()=>import('@/pages/home/index')
        },
        {
          path: '/collect',
          meta: {
            index: 2,
            publicPath: true
          },
          component: ()=>import('@/pages/collect/index')
        },
        {
          path: '/personal',
          meta: {
            index: 3,
            publicPath: true
          },
          component: ()=>import('@/pages/personal/index')
        }
      ],
      redirect:'/home'
    },
    {
      path: '/t1/:id',
      meta: {
        index: 4,
        publicPath: true
      },
      component: ()=>import('@/pages/test/t1')
    },
    {
      path: '/t2',
      meta: {
        index: 4
      },
      component: ()=>import('@/pages/test/t2')
    }
  ]
})
